package com.wdc.domain.strategy.repository;

import com.wdc.domain.strategy.model.entity.StrategyAwardEntity;
import com.wdc.domain.strategy.model.entity.StrategyEntity;
import com.wdc.domain.strategy.model.entity.StrategyRuleEntity;
import com.wdc.domain.strategy.model.valobj.RuleTreeVO;
import com.wdc.domain.strategy.model.valobj.StrategyAwardRuleModelVO;
import com.wdc.domain.strategy.model.valobj.StrategyAwardStockKeyVO;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;

/**
 * 策略存储接口
 */
public interface IStrategyRepository {


    List<StrategyAwardEntity> queryStrategyAwardList(Long strategyId);

    void storeStrategyAwardSearchRateTables(Long strategyId, BigDecimal rateRange, HashMap<Integer, Integer> shuffleStrategyAwardSearchRateTables);

    int getRateRange(Long strategyId);
    int getRateRange(String  key);


    Integer getStrategyAwardAssemble(String key, Integer rateKey);

    void storeStrategyAwardSearchRateTables(String key, Integer rateRange, HashMap<Integer, Integer> shuffleStrategyAwardSearchRateTables);

    StrategyEntity queryStrategyEntityByStrategyId(Long strategyId);

    StrategyRuleEntity queryStrategyRule(Long strategyId, String ruleModel);

    String queryStrategyRuleValue(Long strategyId,  String ruleModel);
    String queryStrategyRuleValue(Long strategyId, Integer awardId, String ruleModel);

    StrategyAwardRuleModelVO queryStrategyAwardRuleModel(Long strategyId, Integer awardId);

    /**
     * 根据规则树ID，查询树结构信息
     * @param treeLock
     * @return
     */
    RuleTreeVO queryRuleTreeVOByTreeId(String treeLock);


    StrategyAwardRuleModelVO queryStrategyAwardRuleModelVO(Long strategyId, Integer awardId);

    /**
     * 缓存奖品库存
     * @param cacheKey
     * @param awardCount
     */

    void cacheStrategyAwardCount(String cacheKey, Integer awardCount);

    /**
     * 缓存key，decr 方式扣减库存
     * @param cacheKey
     * @return
     */
    Boolean subtractionAwardStock(String cacheKey);

    void awardStockConsumeSendQueue(StrategyAwardStockKeyVO build);

    StrategyAwardStockKeyVO takeQueueValue();

    /**
     * 跟新数据库表
     * @param strategyId
     * @param awardId
     */
    void updateStrategyAwardStock(Long strategyId, Integer awardId);

    /**
     * 根据策略ID + 奖品ID的唯一值组合，查询奖品信息
     * @param strategyId
     * @param awardId
     * @return
     */
    StrategyAwardEntity queryStrategyAwardEntity(Long strategyId, Integer awardId);
}



